<?php
	

class SettingModel extends Model{

	protected $tableName = 'settings'; 

	public function getset(){
		$list = $this->select();
		foreach($list as $k => $v){
			$data[$v['key']] = $v['value'];
		}
		return $data;
	}


	/**
	 * 
	 * @param unknown $info    表单信息数组
	 * @return number
	 */
	public function updatevalue($info){
	    
		foreach($info as $k => $v){
    		$map['key']    = $k;
    		$data['value'] = $v;
     		$save = $this->where($map)->save($data);
     		if($save){
     			continue;
     		}else{
     			$has = $this->where($map)->find();
     			if($has){
     				continue;
     			}else{
     				$data2 = array('key'=> $k,'value'=>$v);
     				$save = $this->add($data2);
     			}
     		}
    	}
    	return 1;
	}


    public function getBannerArray(){
        $map['key'] = 'bannernum';
        $num  = $this->where($map)->getField('value');
        $list = D('settings_banner')->limit($num)->select();

        for($i = 0 ; $i< $num ; $i++){
            $list[$i]['id']  = ($list[$i]['id'])?$list[$i]['id']:$i+1;
            $list[$i]['url'] = ($list[$i]['url'])?$list[$i]['url']:'\wkein\Upload\2016-03-08\1.jpg';
            $data[$i] = array(
                'name'=> 'banner-'.$list[$i]['id'],
                'filename'   => 'file-'.$list[$i]['id'],
                'url'   => $list[$i]['url'],
                'imgid' =>'img-'.$list[$i]['id'],
                'inputname' => 'input-'.$list[$i]['id'],
            );
        }

        return $data;
    }

    // 获取第三方代码数组
    public function getThrcode(){
        $array = array(1=>'thr_count',2=>'thr_online',3=>'thr_other');
        foreach($array as $k=> $v){
            $map['key'] = $v;
            $data[$v] = $this->where($map)->getField('value');
        }
        return $data;
    }
}

?>